package cn.fws.meap.utils.logBug;

import com.alibaba.fastjson.JSONObject;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Map;
import java.util.Set;

/**
 * spring工具类
 *
 * @author : jiang
 * @Date: 2019/1/25 10:21
 * @Description:
 */
public class SpringUtil {

    /**
     * 获取请求数据转换成json
     *
     * @param request
     * @return
     * @throws IOException
     */
    public static JSONObject getRequestParam(HttpServletRequest request) throws IOException {

        Map<String, String[]> parameterMap = request.getParameterMap();
        Set<Map.Entry<String, String[]>> entrySet = parameterMap.entrySet();
        JSONObject jsonObject = new JSONObject();
        for (Map.Entry<String, String[]> entry : entrySet) {
            jsonObject.put(entry.getKey(), entry.getValue()[0]);
        }


        // BufferedReader streamReader = new BufferedReader(new InputStreamReader(request.getInputStream(), "UTF-8"));
        // StringBuilder responseStrBuilder = new StringBuilder();
        // String inputStr;
        // while ((inputStr = streamReader.readLine()) != null) {
        //     responseStrBuilder.append(inputStr);
        // }
        // JSONObject jsonObject = JSONObject.parseObject(responseStrBuilder.toString());
        return jsonObject;
    }

}
